package com.example.wly.application_3_homework;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class ColorActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_color);
        Button btnGreen=(Button)findViewById(R.id.btn_green);
        Button btnRed=(Button)findViewById(R.id.btn_red);
        Button btnOrange=(Button)findViewById(R.id.btn_orange);
        MyListener linstener=new MyListener();
        btnGreen.setOnClickListener(linstener);
        btnOrange.setOnClickListener(linstener);
        btnRed.setOnClickListener(linstener);
    }
    class MyListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            ColorDrawable colorDrawable=(ColorDrawable) v.getBackground();
            int colorValue=colorDrawable.getColor();
            Intent intent=new Intent();
            intent.putExtra("color",colorValue);
            setResult(2,intent);
            finish();
        }
    }
}
